package com.atguigu.lease.web.admin.service.impl;

import com.atguigu.lease.model.entity.SystemInfo;
import com.atguigu.lease.model.entity.SystemUser;
import com.atguigu.lease.web.admin.mapper.SystemUserMapper;
import com.atguigu.lease.web.admin.service.SystemPostService;
import com.atguigu.lease.web.admin.service.SystemUserService;
import com.atguigu.lease.web.admin.vo.system.user.SystemUserItemVo;
import com.atguigu.lease.web.admin.vo.system.user.SystemUserQueryVo;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
 * @author 芦博
 * @description 针对表【system_user(员工信息表)】的数据库操作Service实现
 * @createDate 2025 年 11 月 1 日 
 */
@Service
public class SystemUserServiceImpl extends ServiceImpl<SystemUserMapper, SystemUser>
        implements SystemUserService {
    //Mapper层
    @Autowired
    private SystemUserMapper systemUserMapper;
    @Autowired
    private  SystemPostService systemPostService;
    @Override
    public void customQueryPage(IPage<SystemUserItemVo> page, SystemUserQueryVo queryVo) {
         systemUserMapper.customQueryPage(page,queryVo);
    }

    //根据ID查询后台用户信息
    @Override
    public SystemUserItemVo customQueryById(Long id) {
        //获取岗位信息
        SystemUser systemUser = super.getById(id);
        Long postId = systemUser.getPostId();
        SystemInfo systemPostId = systemPostService.getById(postId);
        SystemUserItemVo vo = new SystemUserItemVo();
        String name = systemPostId.getName();
        vo.setPostName(name);
        //复制基本信息
        BeanUtils.copyProperties(systemUser,vo);
        return vo;
    }
    //保存或更新用户信息
    @Override
    public void customSaveOrUpdate(SystemUser ss) {
        //说明: 这里直接可以调用saveOrUpdate方法 , 之所以写下面代码是为了理解单表,模仿之前的多表保存或者更新
        //先删除全部信息 = 更新
        if (ss.getId()!=null){
            //不为空说明有数据 , 直接全部删除,然后再重新保存就行了
            super.removeById(ss.getId());
            super.save(ss);
        }else{
            //到这里就说明一开始就没有数据 直接保存
            super.save(ss);
        }
    }
}




